﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;
using NHibernate.Cfg;
using Sikiedu.Model;
using Sikiedu.Manager;

namespace Sikiedu
{
    class Program
    {
        static void Main(string[] args)
        {
            //var configuration = new Configuration();
            //configuration.Configure(); //解析nhibernate.cfg.xml
            //configuration.AddAssembly("Sikiedu"); //解析映射文件 User.hbm.xml

            //Console.WriteLine("启动成功");


            //ISessionFactory sessionFactory = null;
            //ISession session = null;
            //ITransaction transaction = null;
            //try
            //{
            //    sessionFactory = configuration.BuildSessionFactory();
            //    session = sessionFactory.OpenSession(); // 打开一个跟数据库的会话

            //    //User user = new User() { Username = "sky111", Password = "123456" };
            //    //session.Save(user);


            //    //事务
            //    transaction = session.BeginTransaction();

            //    User user1 = new User() { Username = "shuai003", Password = "123456" };
            //    User user2 = new User() { Username = "shuai004", Password = "123456" };
            //    session.Save(user1);
            //    session.Save(user2);

            //    transaction.Commit();
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e);
            //}
            //finally
            //{
            //    if (transaction != null)
            //    {
            //        transaction.Dispose();
            //    }
            //    if (session != null)
            //    {
            //        session.Close();
            //    }
            //    if (sessionFactory != null)
            //    {
            //        sessionFactory.Close();
            //    }
            //}





            //IUserManager userManager = new UserManager();
            //User user = new User() { Username = "ddddddd", Password = "123456" };
            //userManager.Add(user);


            //IUserManager userManager = new UserManager();
            //User user = new User() {Id = 100002, Username = "修改wxq", Password = "123456" };
            //userManager.Update(user);


            //IUserManager userManager = new UserManager();
            //User user = new User() { Id = 100002};
            //userManager.Remove(user);


            //IUserManager userManager = new UserManager();
            //User user = userManager.GetById(100006);
            //Console.WriteLine(user.Username);
            //Console.WriteLine(user.Password);


            //IUserManager userManager = new UserManager();
            //User user = userManager.GetByUsername("wxq4");
            //Console.WriteLine(user.Id);
            //Console.WriteLine(user.Username);
            //Console.WriteLine(user.Password);


            //IUserManager userManager = new UserManager();
            //ICollection<User> users = userManager.GetAllUsers();
            //foreach (var u in users)
            //{
            //    Console.WriteLine(u.Id + " - " + u.Username + " - " + u.Password);
            //}


            IUserManager userManager = new UserManager();
            bool isUser1 = userManager.VerifyUser("wxq4", "sw");
            bool isUser2 = userManager.VerifyUser("wxq", "sw");
            Console.WriteLine(isUser1);
            Console.WriteLine(isUser2);



            Console.ReadKey();
        }
    }
}
